package edu.msg.hrappy.backend.service.beans;

import edu.msg.hrappy.backend.model.Comment;
import edu.msg.hrappy.backend.repository.CommentRepository;
import edu.msg.hrappy.backend.repository.exception.RepositoryException;
import edu.msg.hrappy.backend.service.CommentService;
import edu.msg.hrappy.backend.service.exception.ServiceException;
import java.util.Collections;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;

@Stateless
public class CommentServiceBean implements CommentService {

    @EJB
    private CommentRepository commentDAO;

    @Override
    public void insert(Comment obj) {

        try {
            commentDAO.insert(obj);
        } catch (RepositoryException e) {
            throw new ServiceException("", e);
        }

    }

    @Override
    public void update(Comment obj) {
        try {
            commentDAO.update(obj);
        } catch (RepositoryException e) {
            throw new ServiceException("", e);
        }

    }

    @Override
    public void delete(Comment obj) {
        try {
            commentDAO.delete(obj);
        } catch (RepositoryException e) {
            throw new ServiceException("", e);
        }

    }

    @Override
    public List<Comment> getAll() {
        List<Comment> all = Collections.emptyList();
        try {
            all = commentDAO.getAll();
        } catch (RepositoryException e) {
            throw new ServiceException("", e);
        }
        return all;
    }

    @Override
    public Comment getById(Long id) {
        Comment one;
        try {
            one = commentDAO.getById(id);
        } catch (RepositoryException e) {
            throw new ServiceException("", e);
        }
        return one;
    }
}
